package com.example.android.adapters

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.ImageView
import android.widget.TextView
import com.example.android.R
import com.example.android.fragments.OnlinePaymentFragment
import com.example.android.models.Pay

/*
*功能：缴费清单adapter
 */

class PayListViewAdapter(val context: Context, var data:List<Pay>) : BaseAdapter() {
    override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
        val vh: ViewHolder
        val view: View
        if (convertView == null) {
            view = LayoutInflater.from(context).inflate(R.layout.pay_item, parent, false);
            vh = ViewHolder(view)
            view.tag = vh
        } else {
            view = convertView
            vh = view.tag as ViewHolder
        }

        //填充数据
        var pay = getItem(position)

            vh.image_item.setImageResource(pay.imageId)
            vh.name_item.text = pay.name
            vh.price_item.text = pay.price


        return view
    }
    private var mListener: OnItemListener? = null

    fun setOnItemListener(mListener: OnItemListener) {
        this.mListener = mListener
    }

    interface OnItemListener {
        fun mAction()
    }

    inner class ViewHolder(v: View) {
        val name_item: TextView = v.findViewById(R.id.name_item)
        val price_item: TextView = v.findViewById(R.id.price_item)
        val image_item: ImageView = v.findViewById(R.id.image_item)
    }

    override fun getItem(position: Int): Pay {
        return data.get(position)
    }

    override fun getItemId(position: Int): Long {
        return position.toLong()
    }

    override fun getCount(): Int {
        return data.size
    }
}